var map;
var marker;
var vn_location = new Array();
vn_location['lat'] = 15.4549;
vn_location['lng'] = 106.5760;
function initialize() {
    var mapOptions = {
        zoom: 5,
        center: new google.maps.LatLng(vn_location['lat'], vn_location['lng']),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

    marker = new google.maps.Marker({
        map: map 
    });

    google.maps.event.addListener(map, 'click', function(event) {
        marker.setPosition(event.latLng);
        $("#longitude").val(event.latLng.lng());
        $("#latitude").val(event.latLng.lat());
    });
    
    
    placeMarker();
}

google.maps.event.addDomListener(window, 'load', initialize);

function placeMarker() {
    var latitude = $("#latitude").val();
    var longitude = $("#longitude").val();
    var latLng = new google.maps.LatLng(latitude, longitude);
    marker.setPosition(latLng);
}

$(document).ready(function(){
    $("#newport").validate({
        rules: {
            'name':         { required: true },
            'description':  { required: true },
            'latitude':     { required: true },
            'longitude':    { required: true }
        }
    });
    $("#newport").submit(function(){
        return $(this).valid();
    });
});